<?php

namespace App\Jobs;

use App\Modules\Admin\Entities\Log\GoodsLogModel;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;

class GoodsLogJobs implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    protected $type;
    protected $goods_log_info;
    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($type,$goods_log_info)
    {
        //
        $this->type = $type;
        $this->goods_log_info = $goods_log_info;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        try {
            GoodsLogModel::getInstance()->createLog($this->type, $this->goods_log_info);
        }catch (\Throwable $e){
            Log::error('写入商品记录发生错误,错误原因:' . $e->getMessage());
        }
        return true;
    }
}
